﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace GestureDemo.Transition
{
    public class SildeTransition : PageTransition
    {
        private FrameworkElement[] frameworkElements = new FrameworkElement[3];
        private TranslateTransform[] transForms = new TranslateTransform[3];

        public override double AnimationDuration
        {
            get
            {
                return 200.0;
            }
        }

        public override void Attach(Panel containerPanel, FrameworkElement pageContainer0, FrameworkElement pageContainer1, FrameworkElement pageContainer2)
        {
            frameworkElements[0] = pageContainer0;
            frameworkElements[1] = pageContainer1;
            frameworkElements[2] = pageContainer2;
            for (int i = 0; i < frameworkElements.Length; i++)
            {
                this.transForms[i] = new TranslateTransform();
                this.frameworkElements[i].RenderTransform = this.transForms[i];
            }
        }

        public override void Detach()
        {
            foreach (FrameworkElement element in frameworkElements)
            {
                element.RenderTransform = null;
            }
        }
        /// <summary>
        /// 改变位置
        /// </summary>
        /// <param name="baseIndex">中间位置</param>
        protected override void ShowPageTransition(int baseIndex,double flickNum)
        {
            int num = (baseIndex + 1) % 3;
            int num2 = (baseIndex + 2) % 3;
            this.transForms[baseIndex].X = -flickNum * this.frameworkElements[num2].ActualWidth;
            this.transForms[num].X = this.transForms[baseIndex].X + this.frameworkElements[baseIndex].ActualWidth;
            this.transForms[num2].X = this.transForms[baseIndex].X - this.frameworkElements[num2].ActualWidth;
        }
    }
}
